package com.kou.controller;/**
 * @author SteinY
 * @create 2022-03-28 13:53
 * @description:
 */

import com.kou.pojo.Type;
import com.kou.service.TypeService;
import com.kou.service.impl.TypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * projectName:myshop2
 * author:SteinY
 * time:2022/3/28 13:53
 * description:
 */
@WebServlet("/deleteType")
public class DeleteType extends HttpServlet {
    TypeService typeService = new TypeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        if (Integer.parseInt(id)<=5){
            response.getWriter().write("0");
        }
        List<Type> types = typeService.findSon(id);
        if (types.size()==0){

                typeService.delete(id);

            response.getWriter().write("1");
        }else {
            response.getWriter().write("0");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}